package cc.booku.owlbox.OnlineDatabase;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;

import java.util.ArrayList;

import cc.booku.owlbox.R;

public class Classity_A extends BaseAdapter implements ListAdapter {


    private ArrayList<Classity_C> classityCArrayList;
    private int id;
    private Context context;
    private LayoutInflater inflater;

    public Classity_A(int sub_item, Context context, ArrayList<Classity_C> classityCArrayList) {
        this.classityCArrayList = classityCArrayList;
        this.context = context;
        this.id = sub_item;
        inflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return classityCArrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return classityCArrayList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @SuppressLint("WrongConstant")
    @Override

    public View getView(int i, View view, ViewGroup viewGroup) {

        TextView vod_class = null;
        TextView count = null;
        Classity_A.ViewHolder viewHolder;
        if (view == null) {
            view = inflater.inflate(id, null);
            vod_class = (TextView) view.findViewById(R.id.vod_class);

            count = (TextView) view.findViewById(R.id.count);
            view.setTag(new ViewHolder(vod_class, count));
        } else {
            Classity_A.ViewHolder viewHolder1 = (Classity_A.ViewHolder) view.getTag(); // 重新获取ViewHolder
            vod_class = viewHolder1.vod_class;
            count = viewHolder1.count;
        }
        Classity_C SubClassc = (Classity_C) classityCArrayList.get(i); // 获取当前项的实例

        count.setText(SubClassc.getCount().toString());//对象为空
        vod_class.setText(SubClassc.getVod_class().toString());

        return view;

    }


    private final class ViewHolder {
        TextView vod_class = null;
        TextView count = null;


        public ViewHolder(TextView vod_class, TextView count) {
            this.vod_class = vod_class;
            this.count = count;
        }

    }

}
